﻿
@{
    ViewData["Title"] = "ImportHeadDiagram";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<form asp-action="ExcelImport" enctype="multipart/form-data" method="post">
    @*<input type="button" class="save" onclick="doUpload()" value="保存" />
        <input type="button" class="return" onclick="GetReturn()" value="返回" />*@
    <input type="hidden" id="guid" value="@ViewData["guid"]" />
    <input type="hidden" id="type" value="@ViewData["type"]" />
</form>

@section Scripts
{
    <script>
        layui.use(['form', 'layedit', 'laydate', 'upload'], function () {
            var form = layui.form, layer = layui.layer, upload = layui.upload, laydate = layui.laydate;
            var imageUrl;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test'
                // , auto: false
                , acceptMime: 'image/*'
                // ,method: 'post' //上传接口的http类型
                , url: 'https://fishopeni.cnfm.com.cn:8095/api/UploadFile/UploadFileBackstage?bllType=' +$('#type').val() + "&type=图片&bllId=" + $('#guid').val()
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res == null) {

                        return layer.msg('上传失败');
                    }
                    else {
                        imageUrl = res[0];
                        return layer.msg('上传成功');
                    }
                    //上传成功
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        });
    </script>
}

<form class="layui-form layui-form-pane layui-upload" lay-filter="formTest" action="">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>首页图上传</legend>
    </fieldset>

    <div class="layui-upload">
        <button type="button" class="layui-btn" id="test">上传图片</button>
        <div class="layui-upload-list">
            <img class="layui-upload-img" id="demo1" style="height:200px;  border:1px solid transparent">
            <p id="demoText"></p>
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            @*<button class="layui-btn" style="width: 100px" lay-submit="" lay-filter="submit">立即提交</button>*@
            @*<button type="reset" style="width: 100px" class="layui-btn layui-btn-primary backIframe">返回</button>*@
            <a style="width: 100px" class="layui-btn layui-btn-primary backIframe" asp-action="Index">返回</a>
        </div>
    </div>
</form>

